package org.springblade.modules.teambition.res;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Data;
import org.springblade.modules.teambition.config.UtcDateDeserializer;

@Data
public class TaskActivityRes {
	String FLOW_CREATE = "create";
	String FLOW_UPDATE = "update.taskflowstatus";
	private String id;
	private String action;
	private String boundToObjectId;
	private String boundToObjectType;
	private String content;
	private String message;
	private String createTime;
	@JsonDeserialize(using = UtcDateDeserializer.class)
	private String updateTime;
	private ActionItem step;

	@Data
	public static class ActionItem{
		String tfsId;
		@JsonDeserialize(using = UtcDateDeserializer.class)
		String updateTime;
	}

	@Data
	public static class LefItem{
		ActionItem task;
	}

	public void extractedItems(){
		if(FLOW_UPDATE.equals(this.action)){
			this.step = JSON.parseObject(this.content,ActionItem.class);
			this.step.setUpdateTime(this.updateTime);
		}else if(FLOW_CREATE.equals(this.action)){
			LefItem lefItem = JSON.parseObject(this.content, LefItem.class);
			this.step = lefItem.task;
			this.step.setUpdateTime(this.updateTime);
		}
	}
}
